<% layout('/layouts/default.html', {title: '种植信息管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(ownMedicinePlantInformation.isNewRecord ? '新增种植信息' : '编辑种植信息')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${ownMedicinePlantInformation}" action="${ctx}/own/ownMedicinePlantInformation/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="id"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种植批次号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input id="batchId" path="batchId" maxlength="25" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('植物名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="varietyName" maxlength="50" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种子/幼体来源')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="seedSource" dictType="own_medicine_seed_source" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种子重量(g)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="seedWeihgt" class="form-control number required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种植区域(亩)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="plantArea" class="form-control number required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('种植周期(月)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="plantCycle" class="form-control number"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('所属区域代码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="areaCode" maxlength="50" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种植时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="plantTime" readonly="true" maxlength="20" class="form-control Wdate required"
									dataFormat="datetime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:true});"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('负责人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="principalName" maxlength="50" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('详细地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="address" maxlength="50" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('产出物名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="outputName" maxlength="50" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('预产重量(kg)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="preWeight" class="form-control number required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="harvestStatus" dictType="own_medicine_plant_harvest_status" class="form-control required" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">添加种植户信息</h4>
				<div class="ml10 mr10">
					<table id="growerChildDataGrid"></table>
					<% if (hasPermi('own:ownMedicinePlantInformation:edit')){ %>
					<a id="growerChildDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10" ><i class="fa fa-plus"></i> 增行</a>
					<% } %>
				</div>
				<h4 class="form-unit">添加田间管理信息</h4>
				<div class="ml10 mr10">
					<table id="fieldChildDataGrid"></table>
					<% if (hasPermi('own:ownMedicinePlantInformation:edit')){ %>
					<a id="fieldChildDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10" ><i class="fa fa-plus"></i> 增行</a>
					<% } %>
				</div>
				<% if(!ownMedicinePlantInformation.isNewRecord){ %>
				<h4 class="form-unit">添加收获信息</h4>
				<div class="ml10 mr10">
					<table id="receiptChildDataGrid"></table>
					<% if (hasPermi('own:ownMedicinePlantInformation:edit')){ %>
					<a id="receiptChildDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10" ><i class="fa fa-plus"></i> 增行</a>
					<% } %>
				</div>
				<% } %>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('own:ownMedicinePlantInformation:edit') && ownMedicinePlantInformation.harvestStatus != '1' && ownMedicinePlantInformation.harvestStatus != '2' ){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
	$.ajax({
		url: "${ctx}/own/ownMedicinePlantInformation/findGrowerAndFieldAndReceipt",
		type: "get",
		data: {"plantId": "${ownMedicinePlantInformation.id}"},
		dataType: "json",
		success: function(data){
			if (data.result){
				//初始化种植户信息子表DataGrid对象
				$("#growerChildDataGrid").dataGrid({
					data: data.grower,
					datatype: "local", // 设置本地数据
					autoGridHeight: function(){return 'auto'}, // 设置自动高度

					// 设置数据表格列
					columnModel: [
						{header:'主键', name:'id', editable:true, hidden:true},
						{header:'种植信息ID', name:'ownMedicinePlantInformationId', editable:true, hidden:true},
						{header:'种植户户主姓名', name:'principalName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'25', 'class':'form-control required', 'rows':'1'}},
						{header:'种植户户主身份证', name:'principalId', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'18', 'class':'form-control idcard required', 'rows':'1'}},
						{header:'联系电话', name:'phone', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'11', 'class':'form-control number required', 'rows':'1'}},
						//{header:'是否为贫困户', name:'isPoor', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'200', 'class':'form-control number', 'rows':'1'}},
						{header:'是否为贫困户', name:'isPoor', width:100,
							editable:true, edittype:'select', editoptions:{'class':'form-control required',
								items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('sys_yes_no')}),
								itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
									$(element).select2().on("change",function(){$(this).resetValid()});
								}
							}
						},
						{header:'备注', name:'remarks', width:150, editable:true, edittype:'textarea', editoptions:{'maxlength':'255', 'class':'form-control number', 'rows':'2'}},
						{header:'操作', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
								var actions = [];
								if (val == 'new'){
									actions.push('<a href="#" onclick="js.confirm(\'你确认要删除这条数据吗？\', function(){$(\'#growerChildDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
								}
								return actions.join('');
							}, editoptions: {defaultValue: 'new'}}
					],

					// 编辑表格参数
					editGrid: true,				// 是否是编辑表格
					editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
					editGridAddRowBtn: $('#growerChildDataGridAddRowBtn'),	// 子表增行按钮
					editGridAddRowInitData: {},	// 新增行的时候初始化的数据

					// 编辑表格的提交数据参数
					editGridInputFormListName: '', // 提交的数据列表名
					editGridInputFormListAttrs: '', // 提交数据列表的属性字段

					// 加载成功后执行事件
					ajaxSuccess: function(data){

					}
				});
				var fieldata = [];
				data.field.forEach((item) => {
					item["dosage"] = item["weight"];
					if (item["type"] == "施肥" || item["type"] == "农药"){
						if(item["type"] == "施肥"){
							item["sefertilization"] = item["specificType"];
						}else {
							item["sepesticide"] = item["specificType"];
						}
					}
					fieldata.push(item);
				})
				//初始化田间管理子表DataGrid对象
				$("#fieldChildDataGrid").dataGrid({
					data: fieldata,
					datatype: "local", // 设置本地数据
					autoGridHeight: function(){return 'auto'}, // 设置自动高度

					// 设置数据表格列
					columnModel: [
						{header:'主键', name:'id', editable:true, hidden:true},
						{header:'种植信息ID', name:'ownMedicinePlantInformationId', editable:true, hidden:true},
						{header:'管理名称', name:'name', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'25', 'class':'form-control', 'rows':'1'}},
						//{header:'管理类型', name:'type', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'18', 'class':'form-control idcard', 'rows':'1'}},
						{header:'管理类型', name:'type', width:100,
							editable:true, edittype:'select', editoptions:{'class':'form-control required',
								items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('own_medicine_field_management_type')}),
								itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
									$(element).select2().on("change",function(){
										$(this).resetValid();
										let elid = $(this).attr("rowid");
										let value = $(this).val();
										if (value == "施肥" || value == "农药"){
											$("#"+elid+"_specificName").removeAttr("readonly");
											$("#"+elid+"_dosage").removeAttr("readonly");
											if(value == "施肥"){
												$("#"+elid+"_sefertilization").removeAttr("disabled");
												$("#"+elid+"_sepesticide").attr("disabled", "disabled");
											}else {
												$("#"+elid+"_sepesticide").removeAttr("disabled");
												$("#"+elid+"_sefertilization").attr("disabled","disabled");
											}
										}else {
											$("#select2-"+elid+"_sefertilization-container").text("");
											$("#"+elid+"_sefertilization option:selected").val("");
											$("#select2-"+elid+"_sepesticide-container").text("");
											$("#"+elid+"_sepesticide option:selected").val("");
											/*console.log($("#"+elid+"_sepesticide option:selected").val())
                                            console.log($("#"+elid+"_sefertilization option:selected").val())*/
											$("#"+elid+"_specificName").val("");
											$("#"+elid+"_weight").val("");
											$("#"+elid+"_sepesticide").attr("disabled", "disabled");
											$("#"+elid+"_sefertilization").attr("disabled","disabled");
											$("#"+elid+"_specificName").attr("readonly","readonly");
											$("#"+elid+"_dosage").attr("readonly", "readonly");
										}
									});
								}
							}
						},
						//{header:'施肥种类', name:'sefertilization', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'11', 'class':'form-control number', 'rows':'1'}},
						{header:'施肥种类', name:'sefertilization', width:100,
							editable:true, edittype:'select', editoptions:{'class':'form-control',
								items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('own_medicine_field_management_fertilization_specific_type')}),
								itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
									$(element).select2().on("change",function(){
										$(this).resetValid()
										let elid = $(this).attr("rowid");
										let value = $(this).val();
										if (value == "其它"){
											$("#"+elid+"_specificName").val("");
										}else {
											$("#"+elid+"_specificName").val($("#"+elid+"_sefertilization option:selected").val() != ""?$("#"+elid+"_sefertilization option:selected").val():$("#"+elid+"_sepesticide option:selected").val());
										}
									});
								}
							}
						},
						//{header:'农药种类', name:'sepesticide', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'11', 'class':'form-control number', 'rows':'1'}},
						{header:'农药种类', name:'sepesticide', width:100,
							editable:true, edittype:'select', editoptions:{'class':'form-control',
								items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('own_medicine_field_management_pesticide_specific_type')}),
								itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
									$(element).select2().on("change",function(){
										$(this).resetValid()
										$(this).resetValid()
										let elid = $(this).attr("rowid");
										let value = $(this).val();
										if (value == "其它"){
											$("#"+elid+"_specificName").val("");
										}else {
											$("#"+elid+"_specificName").val($("#"+elid+"_sefertilization option:selected").val() != ""?$("#"+elid+"_sefertilization option:selected").val():$("#"+elid+"_sepesticide option:selected").val());
										}
									});
								}
							}
						},
						{header:'种类名称', name:'specificName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control', 'rows':'1'}},
						{header:'用量(kg/亩)', name:'dosage', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'11', 'class':'form-control number', 'rows':'1'}},
						{header:'操作时间', name:'addTime', width:150,
							formatter:'date', formatoptions:{srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'},
							editable:true, edittype:'text', editoptions:{'class':'form-control Wdate required', 'readonly':'true',
								dataInit: function(element){ $(element).on('focus', function(){
									WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});
								});
								}}
						},
						{header:'备注', name:'remarks', width:150, editable:true, edittype:'textarea', editoptions:{'maxlength':'255', 'class':'form-control number', 'rows':'2'}},
						{header:'操作', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
								var actions = [];
								if (val == 'new'){
									actions.push('<a href="#" onclick="js.confirm(\'你确认要删除这条数据吗？\', function(){$(\'#fieldChildDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
								}
								return actions.join('');
							}, editoptions: {defaultValue: 'new'}}
					],

					// 编辑表格参数
					editGrid: true,				// 是否是编辑表格
					editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
					editGridAddRowBtn: $('#fieldChildDataGridAddRowBtn'),	// 子表增行按钮
					editGridAddRowInitData: {},	// 新增行的时候初始化的数据

					// 编辑表格的提交数据参数
					editGridInputFormListName: '', // 提交的数据列表名
					editGridInputFormListAttrs: '', // 提交数据列表的属性字段
					// 加载成功后执行事件
					ajaxSuccess: function(data){

					}
				});
				close();
				$("#fieldChildDataGridAddRowBtn").click(function (e) {
					close();
				});

				if ("${ownMedicinePlantInformation.isNewRecord}" == "false"){
					//初始化收获信息子表DataGrid对象
					$("#receiptChildDataGrid").dataGrid({
						data: data.receipt,
						datatype: "local", // 设置本地数据
						autoGridHeight: function(){return 'auto'}, // 设置自动高度

						// 设置数据表格列
						columnModel: [
							{header:'主键', name:'id', editable:true, hidden:true},
							{header:'种植信息ID', name:'ownMedicinePlantInformationId', editable:true, hidden:true},
							{header:'药材批次号', name:'medicineBatchId', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'25', 'class':'form-control required', 'rows':'1'}},
							{header:'药材名称', name:'varietyName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'18', 'class':'form-control required', 'rows':'1'}},
							{header:'药材重量(g)', name:'weight', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'11', 'class':'form-control number required', 'rows':'1'}},
							{header:'所属区域代码', name:'areaCode', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'18', 'class':'form-control required', 'rows':'1'}},
							//{header:'收获时间', name:'harvestTime', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'18', 'class':'form-control', 'rows':'1'}},
							{header:'收获时间', name:'harvestTime', width:150,
								formatter:'date', formatoptions:{srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'},
								editable:true, edittype:'text', editoptions:{'class':'form-control Wdate required', 'readonly':'true',
									dataInit: function(element){ $(element).on('focus', function(){
										WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});
									});
									}}
							},
							{header:'种子来源', name:'seedSource', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'18', 'class':'form-control required', 'rows':'1'}},
							{header:'施肥情况', name:'fertilizer', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'18', 'class':'form-control required', 'rows':'1'}},
							{header:'喷药情况', name:'pesticide', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'18', 'class':'form-control required', 'rows':'1'}},
							{header:'备注', name:'remarks', width:150, editable:true, edittype:'textarea', editoptions:{'maxlength':'255', 'class':'form-control number required', 'rows':'2'}},
							{header:'操作', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
									var actions = [];
									if (val == 'new'){
										actions.push('<a href="#" onclick="js.confirm(\'你确认要删除这条数据吗？\', function(){$(\'#receiptChildDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
									}
									return actions.join('');
								}, editoptions: {defaultValue: 'new'}}
						],

						// 编辑表格参数
						editGrid: true,				// 是否是编辑表格
						editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
						editGridAddRowBtn: $('#receiptChildDataGridAddRowBtn'),	// 子表增行按钮
						editGridAddRowInitData: {},	// 新增行的时候初始化的数据

						// 编辑表格的提交数据参数
						editGridInputFormListName: '', // 提交的数据列表名
						editGridInputFormListAttrs: '', // 提交数据列表的属性字段

						// 加载成功后执行事件
						ajaxSuccess: function(data){
						}
					});
					assig();
					getSFandPY();
					$("#receiptChildDataGridAddRowBtn").click(function (e) {
						assig();
					});
				}
			}else {
				js.showErrorMessage(`获取失败！`);
			}
		},
		error: function(e){
			js.showErrorMessage("错误",e);
		}

	});

</script>
<script id="listselectTpl" type="text/template">//<!--<div>
<#form:listselect id="{{d.id}}" title="{{d.title}}" name="{{d.name}}" value="{{d.value}}"
	labelName="{{d.labelName}}" labelValue="{{d.labelValue}}" url="{{d.url}}"
	itemCode="{{d.itemCode}}" itemName="{{d.itemName}}"
	class="{{d.cssClass}}" btnClass="btn-sm" allowClear="true"/>
</div>//--></script>
<script>
	var sf = "";
	var py = "";
	var ly = "";
	$(function(){
		var status = "${ownMedicinePlantInformation.harvestStatus}";
		if (status == '2') {
			var nodeList = $("input");
			for (var i = 0; i < nodeList.length; i++) {
				nodeList[i].disabled = true;
			}
			$("textarea").attr("disabled", "disabled");
		}
		var jsaa = "${ownMedicinePlantInformation.isNewRecord}"; //获取beetl的值
		if (jsaa == 'false')
			$("#batchId").attr("disabled","disabled");
		close();

	});
	function getSFandPY(){
		$.ajax({
			url: "${ctx}/own/ownMedicineFieldManagement/findByType",
			type: "get",
			data: {"plantId": "${ownMedicinePlantInformation.id}"},
			dataType: "json",
			success: function(data){
				if (data.success){
					if (data.sf){
						//喷药
						sf = '已施肥';
					}else {
						sf = '未施肥';
					}
					if(data.py){
						//施肥
						py = '已喷药';
					}else {
						py = '未喷药';
					}
					ly = "${ownMedicinePlantInformation.seedSource}";
					assig();
				}else {
					js.showErrorMessage("获取失败，错误信息"+data.msg+"!");
				}
			},
			error: function(e){
				js.showErrorMessage("错误",e);
			}

		});
	}
	function getChildData(name, reobj, type){
		/**
		 * 获取子表数据
		 * name: 名称
		 * reobj: 需要组装成的对象
		 * 返回：子表数组
		 **/
		let ids = $('#'+name).dataGrid('getDataIDs');
		var childData = []; //用来存储种植户子数据
		for (let id of ids){
			var obj = {
				'id': $('#'+id+'_id').val(),
				'ownMedicinePlantInformationId': $('#'+id+'_ownMedicinePlantInformationId').val(),
			};
			for (let key in reobj){
				obj[key] = $('#'+id+'_'+key).val();
				if (type == 1 && key == 'specificType'){
					obj[key] = $('#'+id+'_sefertilization').val() != ""?$('#'+id+'_sefertilization').val():$('#'+id+'_sepesticide').val();
				}
				if (type == 1 && key == 'weight'){
					obj[key] = $('#'+id+'_dosage').val();
				}

			}
			let temp = false;//判断是否为空对象
			for (let key in obj){
				if (obj[key]){
					temp = true;
					break;
				}
			}
			if (temp){
				childData.push(obj);
			}
		}
		return childData;
	};
	$("#inputForm").validate({
		submitHandler: function(form){
			var growerobj = {'batchId': '', 'principalName': '', 'principalId': '', 'phone': '', 'isPoor': '', 'remarks': ''};
			var growerChildData = getChildData('growerChildDataGrid', growerobj, 0); //用来存储种植户子数据
			var fieldobj = {"batchId": "", "name": "", "type": "", "specificType": "", "specificName": "", "weight": "", "addTime": "","remarks": ""};
			var fieldChildData = getChildData('fieldChildDataGrid', fieldobj, 1); //用来存储田间管理子数据
			var receiptobj = {
				"batchId": "",
				"medicineBatchId": "",
				"varietyName": "",
				"weight": "",
				"harvestTime": "",
				"areaCode": "",
				"seedSource": "",
				"fertilizer": "",
				"pesticide": "",
				"remarks": ""};
			var receiptChildData = getChildData('receiptChildDataGrid', receiptobj, 2); //用来存储种收获子数据
			var contentsData = {
				"id": $("#id").val(),"batchId": $("#batchId").val(),"varietyName": $("#varietyName").val(),
				"seedSource": $("input[name='seedSource']:checked").val(),"seedWeihgt": $("#seedWeihgt").val(),"plantArea": $("#plantArea").val(),
				"plantCycle": $("#plantCycle").val(), "areaCode": $("#areaCode").val(), "plantTime": $("#plantTime").val(),
				"principalName": $("#principalName").val(), "address": $("#address").val(), "outputName": $("#outputName").val(),
				"preWeight": $("#preWeight").val(), "harvestStatus": $("input[name='harvestStatus']:checked").val(), "remarks": $("#remarks").val()
			}
			for (let index in growerChildData) {
				var item = growerChildData[index];
				contentsData["ownMedicineGrowerInformationList["+index+"].id"]= item["id"];
				contentsData["ownMedicineGrowerInformationList["+index+"].batchId"]= $("#batchId").val();
				contentsData["ownMedicineGrowerInformationList["+index+"].principalName"]= item["principalName"];
				contentsData["ownMedicineGrowerInformationList["+index+"].ownMedicinePlantInformationId"]= item["ownMedicinePlantInformationId"];
				contentsData["ownMedicineGrowerInformationList["+index+"].principalId"]= item["principalId"];
				contentsData["ownMedicineGrowerInformationList["+index+"].phone"]= item["phone"];
				contentsData["ownMedicineGrowerInformationList["+index+"].isPoor"]= item["isPoor"];
				contentsData["ownMedicineGrowerInformationList["+index+"].remarks"]= item["remarks"];
			}
			for (let index in fieldChildData) {
				var item = fieldChildData[index];
				contentsData["ownMedicineFieldManagementList["+index+"].id"]= item["id"];
				contentsData["ownMedicineFieldManagementList["+index+"].batchId"]= $("#batchId").val();
				contentsData["ownMedicineFieldManagementList["+index+"].name"]= item["name"];
				contentsData["ownMedicineFieldManagementList["+index+"].ownMedicinePlantInformationId"]= item["ownMedicinePlantInformationId"];
				contentsData["ownMedicineFieldManagementList["+index+"].type"]= item["type"];
				contentsData["ownMedicineFieldManagementList["+index+"].specificType"]= item["specificType"];
				contentsData["ownMedicineFieldManagementList["+index+"].specificName"]= item["specificName"];
				contentsData["ownMedicineFieldManagementList["+index+"].weight"]= item["weight"];
				contentsData["ownMedicineFieldManagementList["+index+"].addTime"]= item["addTime"];
				contentsData["ownMedicineFieldManagementList["+index+"].remarks"]= item["remarks"];
			}
			for (let index in receiptChildData) {
				var item = receiptChildData[index];
				contentsData["ownMedicineReceiptInformationList["+index+"].id"]= item["id"];
				contentsData["ownMedicineReceiptInformationList["+index+"].batchId"]= $("#batchId").val();
				contentsData["ownMedicineReceiptInformationList["+index+"].name"]= item["name"];
				contentsData["ownMedicineReceiptInformationList["+index+"].ownMedicinePlantInformationId"]= item["ownMedicinePlantInformationId"];
				contentsData["ownMedicineReceiptInformationList["+index+"].medicineBatchId"]= item["medicineBatchId"];
				contentsData["ownMedicineReceiptInformationList["+index+"].varietyName"]= item["varietyName"];
				contentsData["ownMedicineReceiptInformationList["+index+"].harvestTime"]= item["harvestTime"];
				contentsData["ownMedicineReceiptInformationList["+index+"].weight"]= item["weight"];
				contentsData["ownMedicineReceiptInformationList["+index+"].areaCode"]= item["areaCode"];
				contentsData["ownMedicineReceiptInformationList["+index+"].seedSource"]= item["seedSource"];
				contentsData["ownMedicineReceiptInformationList["+index+"].fertilizer"]= item["fertilizer"];
				contentsData["ownMedicineReceiptInformationList["+index+"].pesticide"]= item["pesticide"];
				contentsData["ownMedicineReceiptInformationList["+index+"].remarks"]= item["remarks"];
			}
			$.ajax({
				url: "${ctx}/own/ownMedicinePlantInformation/save",
				type: "post",
				dataType: "json",
				data: contentsData,
				success: function(data){
					if (data.result && data.data.id){
						js.showMessage("出库成功!");
						js.closeCurrentTabPage(function(contentWindow){
							contentWindow.page();
						});
					}else {
						js.showErrorMessage("出库失败!");
					}
				},
				error: function(e){
					js.showErrorMessage("错误",e);
				}
			})
		}
	});
	function close(){
		$("select[name='sefertilization']").attr("disabled","disabled");
		$("select[name='sepesticide']").attr("disabled","disabled");
		$("input[name='specificName']").attr("readonly","readonly");
		$("input[name='dosage']").attr("readonly","readonly");
	}
	function assig(){
		$("input[name='seedSource']").val(ly);
		$("input[name='fertilizer']").val(sf);
		$("input[name='pesticide']").val(py);
		$("input[name='seedSource']").attr("readonly","readonly");
		$("input[name='fertilizer']").attr("readonly","readonly");
		$("input[name='pesticide']").attr("readonly","readonly");
	}
</script>